const uploadService = require("../services/uploadServices");
const { successResponse, errorResponse } = require("../utils/response");

exports.upload = async (ctx) => {
  try {
    const file = ctx.request.files.file;
    if (!file) ctx.body = errorResponse({}, "获取文件失败");
    const result = await uploadService.uploadFile(file);

    if (result) {
      ctx.body = successResponse(true, "上传文件成功");
    } else {
      ctx.body = errorResponse({}, "上传文件失败");
    }
  } catch (error) {
    ctx.body = errorResponse(error, "上传文件失败");
  }
};
